﻿<template>
  <a-modal
    title="编辑短信平台配置信息"
    width="40%"
    :visible="visible"
    :confirmLoading="loading"
    @ok="handleSubmit"
    @cancel="()=>{this.visible=false}"
  >
    <a-spin :spinning="loading">
      <a-form-model ref="form" :model="entity" :rules="rules" v-bind="layout">
        <a-form-model-item label="排序" prop="Sort">
          <a-input v-model="entity.Sort" autocomplete="off" placeholder="越小越靠前" />
        </a-form-model-item>
        <a-form-model-item label="短信API秘钥ID" prop="M_AccessKeyID">
          <a-input v-model="entity.M_AccessKeyID" autocomplete="off" placeholder="短信API秘钥ID" />
        </a-form-model-item>
        <a-form-model-item label="短信API秘钥" prop="M_AccessKeySecret">
          <a-input v-model="entity.M_AccessKeySecret" autocomplete="off" placeholder="短信API秘钥" />
        </a-form-model-item>
        <a-form-model-item label="短信签名名称" prop="M_SignName">
          <a-input v-model="entity.M_SignName" autocomplete="off" placeholder="短信签名名称" />
        </a-form-model-item>
        <a-form-model-item label="短信模板ID" prop="M_TemplateCode">
          <a-input v-model="entity.M_TemplateCode" autocomplete="off" placeholder="短信模板ID" />
        </a-form-model-item>
        <a-form-model-item label="上行短信扩展码" prop="M_SmsUpExtendCode">
          <a-input v-model="entity.M_SmsUpExtendCode" autocomplete="off" placeholder="上行短信扩展码" />
        </a-form-model-item>
        <a-form-model-item label="外部流水扩展字段" prop="M_OutId">
          <a-input v-model="entity.M_OutId" autocomplete="off" placeholder="外部流水扩展字段" />
        </a-form-model-item>
        <a-form-model-item label="自定义编码" prop="Code">
          <a-input v-model="entity.Code" autocomplete="off" placeholder="自定义编码" />
        </a-form-model-item>
        <a-form-model-item label="短信配置备注" prop="Remark">
          <a-input v-model="entity.Remark" autocomplete="off" placeholder="短信配置备注" />
        </a-form-model-item>
      </a-form-model>
    </a-spin>
  </a-modal>
</template>

<script>
export default {
  props: {
    // eslint-disable-next-line vue/require-default-prop
    parentObj: Object
  },
  data () {
    return {
      layout: {
        labelCol: { span: 5 },
        wrapperCol: { span: 18 }
      },
      visible: false,
      loading: false,
      entity: {},
      rules: {
        M_AccessKeyID: [{ required: true, message: '必填' }],
        M_AccessKeySecret: [{ required: true, message: '必填' }],
        M_SignName: [{ required: true, message: '必填' }],
        M_TemplateCode: [{ required: true, message: '必填' }]
      },
      title: ''
    }
  },
  methods: {
    init () {
      this.visible = true
      this.entity = {}
      this.$nextTick(() => {
        this.$refs['form'].clearValidate()
      })
    },
    openForm (id, title) {
      this.init()

      if (id) {
        this.loading = true
        this.$http.post('/Base_Manage/Base_SMSConfig/GetTheData', { id: id }).then(resJson => {
          this.loading = false

          this.entity = resJson.Data
        })
      }
    },
    handleSubmit () {
      this.$refs['form'].validate(valid => {
        if (!valid) {
          return
        }
        this.loading = true
        this.$http.post('/Base_Manage/Base_SMSConfig/SaveData', this.entity).then(resJson => {
          this.loading = false

          if (resJson.Success) {
            this.$message.success('操作成功!')
            this.visible = false

            this.parentObj.getDataList()
          } else {
            this.$message.error(resJson.Msg)
          }
        })
      })
    }
  }
}
</script>
